'use strict';
const db = uniCloud.database()
const coll = db.collection('user')
const dbCmd = db.command
exports.main = async (event, context) => {

	let res1 = await coll.where({
		_id: event.openid
	}).get()
	console.log('res1', res1)
	if (res1.data[0].youxijihui != 0) {
		let res = await coll.where({
			_id: event.openid
		}).update({
			youxijihui: dbCmd.inc(-1),
			toupiaojihui: dbCmd.inc(1)
		})

		return await coll.where({
			_id: event.openid
		}).get()
	} else {
		return res1
	}


};
